<?php
require("../../../../../libraries/config.php");
require("../../../../../libraries/dbclass2.php");

function xcrud_remove_post_report($id){
	$db=new db;
	$db->connect();
	$db->query('select * from index_post where id='.$id);
	$rc=$db->fetchOne();
		$pid=$rc['post_id'];
		$db->nonquery('delete from index_post where id='.$id);
	if($rc['is_image']==1){
	
		$db->nonquery('delete from images where post_id='.$pid);
		$db->nonquery('delete from post_image where id='.$pid);
	}else
	if($rc['is_video']==1){
		$db->nonquery('delete from post_media where id='.$pid);
	}else
	if($rc['is_text']==1){
		$db->nonquery('delete from post_text where id='.$pid);
	}
	$sql="update users set report=report+1 where username='".$rc['username']."'";
	$db->nonquery($sql);
	
	
	$db->close();


}





function publish_action($xcrud)
{
    if ($xcrud->get('primary'))
    {
        $db = Xcrud_db::get_instance();
        $query = 'UPDATE truyen SET `xoa` = b\'1\' WHERE id = ' . (int)$xcrud->get('primary');
        $db->query($query);
    }
}
function unpublish_action($xcrud)
{
    if ($xcrud->get('primary'))
    {
        $db = Xcrud_db::get_instance();
        $query = 'UPDATE truyen SET `xoa` = b\'0\' WHERE id = ' . (int)$xcrud->get('primary');
        $db->query($query);
    }
}
function publish_action2($xcrud)
{
    if ($xcrud->get('primary'))
    {
        $db = Xcrud_db::get_instance();
        $query = 'UPDATE truyen_chuong SET `xoa` = b\'1\' WHERE id = ' . (int)$xcrud->get('primary');
        $db->query($query);
    }
}
function unpublish_action2($xcrud)
{
    if ($xcrud->get('primary'))
    {
        $db = Xcrud_db::get_instance();
        $query = 'UPDATE truyen_chuong SET `xoa` = b\'0\' WHERE id = ' . (int)$xcrud->get('primary');
        $db->query($query);
    }
}



function delete_report($xcrud)
{
    if ($xcrud->get('postid'))
    {
		
		$db = Xcrud_db::get_instance();
        $query = 'update report_post set xuly=1 WHERE id = ' . (int)$xcrud->get('primary');
        $db->query($query);
	//	xcrud_remove_post_report((int)$xcrud->get('postid'));
		xcrud_remove_post_report($xcrud->get('postid'));
	
		
      
    }
}

function breakline($value, $field, $primary_key, $list, $xcrud)
{
   	return  '<textarea " name="'.$fieldname.'" class="xcrud-textarea" >'.nl2br($value).'</textarea>';
       
}

?>
